import cv2


def drawShape(src, points):
    i = 0
    while i < len(points):
        if i == len(points) - 1:
            x, y = points[i][0]
            x1, y1 = points[0][0]
        else:
            x, y = points[i][0]
            x1, y1 = points[i + 1][0]

        cv2.line(src, (x, y), (x1, y1), (0, 0, 255), 4)
        i = i + 1


img = cv2.imread('../asset/cube.jpeg')
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

ret, binary = cv2.threshold(img_gray, 150, 255, cv2.THRESH_BINARY)

contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
e = 20
hull = cv2.convexHull(contours[1], e, True)
drawShape(img, hull)

while True:
    cv2.imshow('img', img)
    key = cv2.waitKey(10)
    if key & 0xFF == ord('q'):
        break
cv2.destroyAllWindows()
